<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>JS实现计时器(时、分，秒)</title> 
</head>
<!-- September 19 2016 -->
<body> 
<span id=nowtime></span>
<script>
	//距离2016-09-19已经过去的时间	20160919
	function getTheTime(){
		var t=new Date() - new Date(2016,8,19);
		var y=Math.floor(t/1000/60/60/24/365);
		t-=y*1000*60*60*24*365;
		var d=Math.floor(t/1000/60/60/24);
		t-=d*1000*60*60*24;
		var h=Math.floor(t/1000/60/60);
		t-=h*1000*60*60;
		var m=Math.floor(t/1000/60);
		t-=m*1000*60;
		var s=Math.floor(t/1000);
		return y+"年"+d+"天"+h+"时"+m+"分"+s+"秒";
	}
	window.onload=function(){
		setInterval("nowtime.innerHTML=getTheTime();",1000);
	}
</script>
</body> 
</html> 